VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ClsCaractGrvCli"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

'Clase de caracteristicas_grupo_venta_automatica_cliente
Public WithEvents orset As ClsRecordset
Attribute orset.VB_VarHelpID = -1

Public Event DataChanged()

'Miembros de la Clase
Public codigo As String
Public codCliente As String
Public codGrupoVau As String
Public codDetalle As String
Public generar_ventas As Boolean
Public periodo_facturacion As Integer
Public maxven_np As Integer
Public cant_dtas_fact As Integer
Public per_fact_actual As Integer
'Cliente
Public cliente As ClsCliente

'Constructor y Destructor
Private Sub Class_Initialize()
    Set orset = New ClsRecordset
    Set cliente = New ClsCliente
    orset.setCampos concatenaVectores(dbCampos(cgc), dbCampos(cli))
    orset.setTablas Array(cgc, cli)
End Sub
Private Sub Class_Terminate()
    Set orset = Nothing
End Sub
' Generic Data management methods
Public Sub consulta(optgrvcod As String, Optional optCliCod As String = "", Optional optSoloParaGenerarVentas As Boolean = False, Optional optSoloClientesHabilitados As Boolean = False)
    Dim conds As Variant
    conds = Array(cgc_cli_id & "=" & cli_id)
    If optgrvcod <> "" Then
        conds = concatenaVectores(conds, Array(cgc_grv_id & "=" & optgrvcod))
    End If
    If optCliCod <> "" Then
        conds = concatenaVectores(conds, Array(cli_id & "='" & optCliCod & "'"))
    End If
    If optSoloParaGenerarVentas Then
        conds = concatenaVectores(conds, Array(cgc_generar_ventas & "=1"))
    End If
    If optSoloClientesHabilitados Then
        conds = concatenaVectores(conds, Array(cli_estado & "=1"))
    End If
    orset.consulta conds, Array(cli_nombre & " ASC")
End Sub
Public Sub consultaXClienteCod(optClienteCod As String, optGrupoVauCod As String)
    orset.consulta Array(cgc_cli_id & "=" & cli_id, _
                         cgc_grv_id & "=" & optGrupoVauCod, _
                         cgc_cli_id & "='" & optClienteCod & "'")
    orset.CierraRec
End Sub
Public Sub consultaDatos(codig As String)
    orset.consulta Array(cgc_cli_id & "=" & cli_id, _
                         cgc_id & "=" & codig)
    orset.CierraRec
End Sub
Public Sub actualizaPagosAdelantadosMultiperiodo(optgrvcod As String, codigoDetalle As String)
    Dim sql1 As ClsSQL
    Set sql1 = New ClsSQL
    sql1.setCampos Array(cli_id)
    sql1.setTablas Array(cli, aso, tra, tdt)
    sql1.setCondiciones Array(aso_cli_id & "=" & cli_id, _
                              tra_cli_id & "=" & cli_id, _
                              tdt_tra_id & "=" & tra_id, _
                              aso_baja & "=''", _
                              tdt_dta_id & "=" & codigoDetalle)
    'disminuye en uno el periodo actual si es que estuviera en mas de uno
    orset.sUpdateGral Array(cgc_per_fact_actual), _
                      Array(cgc_per_fact_actual & " - 1"), _
                      Array(cgc), _
                      Array(cgc_grv_id & "=" & optgrvcod, _
                            cgc_per_fact_actual & " > 1", _
                            cgc_periodo_facturacion & " > 1", _
                            cgc_cli_id & " IN (" & sql1.sSelect & ")"), False
    'reinicia el contador de periodo actual si es que estuviera en uno (para que no llegue a cero)
    orset.sUpdateGral Array(cgc_per_fact_actual), _
                      Array(cgc_periodo_facturacion), _
                      Array(cgc), _
                      Array(cgc_grv_id & "=" & optgrvcod, _
                            cgc_per_fact_actual & " = 1", _
                            cgc_periodo_facturacion & " > 1", _
                            cgc_cli_id & " IN (" & sql1.cadena & ")"), False
End Sub
Private Sub Reload_members()
    With orset
        codigo = .getDato(cgc_id)
        codCliente = .getDato(cgc_cli_id)
        codGrupoVau = .getDato(cgc_grv_id)
        codDetalle = .getDato(cgc_dta_id)
        generar_ventas = .getDato(cgc_generar_ventas)
        periodo_facturacion = .getDato(cgc_periodo_facturacion)
        maxven_np = .getDato(cgc_maxven_np)
        cant_dtas_fact = .getDato(cgc_cant_dtas_fact)
        per_fact_actual = .getDato(cgc_per_fact_actual)
        'si estuviera insertando/modificando/eliminando consulta los datos de la BD
        If .registrando Then
            cliente.consultaDatos codCliente
            .registrando = False
        Else
            cliente.Reload_members orset
        End If
    End With
    RaiseEvent DataChanged
End Sub
'metodos de bd
Public Sub Nuevo(newCliId As String, newGrvId As String, newDtaId As String, newGenerarVentas As String, newPeriodoFacturacion As String, newMaxvenNp As String, newCantDtasFact As String, newPerFactActual As String)
    orset.sInsert Array("", newCliId, newGrvId, newDtaId, formatBoolBD(newGenerarVentas), newPeriodoFacturacion, newMaxvenNp, newCantDtasFact, newPerFactActual)
End Sub
Public Sub Modificar(codig As String, newCliId As String, newGrvId As String, newDtaId As String, newGenerarVentas As String, newPeriodoFacturacion As String, newMaxvenNp As String, newCantDtasFact As String, newPerFactActual As String)
    orset.sUpdate Array(codig, newCliId, newGrvId, newDtaId, formatBoolBD(newGenerarVentas), newPeriodoFacturacion, newMaxvenNp, newCantDtasFact, newPerFactActual)
End Sub
Public Sub Borrar(codig As String)
    orset.sDelete codig
End Sub

Private Sub orset_DataChanged()
    Reload_members
End Sub
